﻿//Created by Action Script Viewer - http://www.buraks.com/asv
package net.wooga.pets.controllers {
    import flash.events.*;
    import net.wooga.pets.events.*;
    import net.wooga.pets.interfaces.*;
    import net.wooga.pets.constants.*;
    import org.robotlegs.mvcs.*;
    import net.wooga.pets.models.world.*;

    public class ShowThankYouAniCommand extends Command implements ITicking {

        public var event:InfoEvent;
        public var world:WorldModel;
        private var _aniDuration:int;

        private static const ANI_DUARTION:int = 3;

        override public function execute():void{
            this.showThankYouAnimation((this.event.info as ITreatable));
        }
        private function showThankYouAnimation(_arg1:ITreatable):void{
            if (!_arg1){
                return;
            };
            if (!_arg1.currentTreatment){
                dispatch(new InfoEvent(EventConstants.STOP_MOVING, _arg1.id));
                _arg1.canWalk = false;
                dispatch(new InfoEvent(EventConstants.DISABLE_PET_VIEW, _arg1.id));
                dispatch(new InfoEvent(EventConstants.DISABLE_VIEW, _arg1.id));
                this._aniDuration = ANI_DUARTION;
                dispatch(new TickingEvent(TickingEvent.ADD_TICKING, this, TimeConstants.SECOND));
            };
            var _local2:Object = (_arg1.currentTreatment) ? null : {animationState:"idleThankyou"};
            dispatch(new InfoEvent(EventConstants.UPDATE_ACTOR, _arg1.id, _local2));
            this.continueTreatments(_arg1);
        }
        public function onTick(_arg1:Boolean=true, _arg2:Number=0):void{
            var _local3:ITreatable;
            this._aniDuration--;
            if (!this._aniDuration){
                dispatch(new TickingEvent(TickingEvent.REMOVE_TICKING, this));
                _local3 = (this.event.info as ITreatable);
                _local3.canWalk = true;
                dispatch(new InfoEvent(EventConstants.ENABLE_PET_VIEW, _local3.id));
                dispatch(new InfoEvent(EventConstants.START_MOVING, _local3.id));
                this.handleNextTreatment(_local3);
            };
        }
        private function continueTreatments(_arg1:ITreatable):void{
            this.handleNextTreatment(_arg1);
            dispatch(new Event(EventConstants.HANDLE_NEXT_AVATAR_ACTION));
            _arg1.removeSpeechBubble();
        }
        private function handleNextTreatment(_arg1:ITreatable):void{
            if (_arg1.currentTreatment){
                _arg1.moveToNextTreatment();
            } else {
                if (_arg1.diseaseName == WorldConstants.DISEASE_OLD){
                    _arg1.moveToNextTarget(GameConstants.TYPE_KINDERGARTEN);
                } else {
                    _arg1.moveToNextTarget(GameConstants.TYPE_ENTRANCE_AREA);
                };
                if (_arg1.canWalk){
                };
            };
        }

    }
}//package net.wooga.pets.controllers 
